package com.insigma.business.qrcode.appmgt.service.impl;

import com.alibaba.excel.EasyExcel;
import com.insigma.business.qrcode.appmgt.dto.excel.SoldierPretreatCardTemplateDTO;
import com.insigma.business.qrcode.appmgt.dto.excel.SoldierPretreatCardWriteHandler;
import com.insigma.business.qrcode.appmgt.service.SoldierPretreatCardService;
import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.common.template.area.BaseProviderImpl;
import com.insigma.business.qrcode.common.vo.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service("soldierPretreatCardService")
public class SoldierPretreatCardServiceImpl extends BaseProviderImpl implements SoldierPretreatCardService {
    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    @Override
    public void downloadTemplate(HttpServletResponse response) throws IOException {
        List<String> genderList = new ArrayList<>();
        genderList.add("男");
        genderList.add("女");
        genderList.add("保密");

        List<String> pretreatCardTypeList = new ArrayList<>();
        pretreatCardTypeList.add("退役军人优待证01");
        pretreatCardTypeList.add("退役军人优待证02");
        pretreatCardTypeList.add("退役军人优待证03");

        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("优待证导入模板文件.xlsx", "UTF-8"));
        EasyExcel.write(response.getOutputStream(), SoldierPretreatCardTemplateDTO.class).registerWriteHandler(new SoldierPretreatCardWriteHandler(genderList,pretreatCardTypeList)).sheet("sheet1").doWrite(new ArrayList<>());
    }

    @Override
    public BaseResponse<String> importCourtCardInfo(MultipartFile file) {
        return null;
    }
}
